package br.com.estudante.mvc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.estudante.mvc.logica.Logica;

@WebServlet(name="Servlet de Controle", urlPatterns="/mvc")
public class ControllerServlet extends HttpServlet {
	
	protected void service(HttpServletRequest request, 
			HttpServletResponse response)
			throws ServletException, IOException {
		
		String parametro = request.getParameter("logica");
		String nomeDaClasse = 
				"br.com.estudante.mvc.logica." + parametro;
		
		try {
			Class classe = Class.forName(nomeDaClasse);
			Logica logica = (Logica)classe.newInstance();
			logica.executa(request, response);
			
		} catch (Exception e) {
			throw new ServletException(
					"Houve um erro no processamento", e);
		}
	}
	

}
